package Zuoye.zuoye5;

import org.w3c.dom.ls.LSOutput;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Scanner;

public class Fangfa {
    Scanner sc = new Scanner(System.in);
    ArrayList<Goods> list = new ArrayList<>();

    public void show() {

        list.add(new Goods("华为Mate50Pro", 3));
        list.add(new Goods("鸭蛋", 5));
        list.add(new Goods("风扇", 1));
        list.add(new Goods("项链", 2));
        System.out.println("欢迎来到秒杀抢购活动");
        System.out.println("请选择您要抢购的商品：");
        String name = sc.next();
        for (int i = 0; i < list.size(); i++) {
            if (name.equals(list.get(i).getName())   && times()  && list.get(i).getCount() > 0){
                System.out.println("抢购成功");
                return;
            }
        }
        System.out.println("抢购失败");
    }


    public boolean  times() {
        System.out.println("下单时间：");
        String time = sc.next();

        String na = "2025-07-1113:35:55";
        String end = "2025-07-1113:45:55";
        DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-ddHH:mm:ss");
        LocalDateTime start = LocalDateTime.parse(na, dtf);
        LocalDateTime end1 = LocalDateTime.parse(end, dtf);
        LocalDateTime time1 = LocalDateTime.parse(time, dtf);
        if (time1.isAfter(start) && time1.isBefore(end1)) {
            System.out.println("下单成功");
            return true;
        } else {
            System.out.println("下单失败");
            return false;
        }

    }
}
